package com.open.init.version;

import com.open.bean.AiDrawServer;
import com.open.service.AiDrawServerService;
import com.open.service.OpenDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author tanyongpeng
 * <p>des</p>
 **/
@Slf4j
@Component
public class VersionRunner implements ApplicationRunner {

    @Autowired
    OpenDictService openDictService;

    @Autowired
    AiDrawServerService aiDrawServerService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        int version = Integer.parseInt(openDictService.getDict("100005"));
        log.info("开始初始化版本.....");
        log.info("当前版本：{}",version);
        version ++;
        log.info("升级后");
        openDictService.setDict("100005",version);
        log.info("当前版本：{}",version);

        Integer count = aiDrawServerService.lambdaQuery().eq(AiDrawServer::getServerType, 0).count();
        if (count == 0){
            log.info("初始化。。。。公共服务器");
            AiDrawServer aiDrawServer = new AiDrawServer();
            aiDrawServer.setServerName("公共的绘画区域");
            aiDrawServer.setServerType(0);
            aiDrawServer.setServerCount(1);
            aiDrawServer.setServerIcon("<svg t=\"1682877147853\"class=\"icon\"viewBox=\"0 0 1024 1024\"version=\"1.1\"xmlns=\"http://www.w3.org/2000/svg\"p-id=\"7644\"><path d=\"M512 512m-463.584 0a463.584 463.584 0 1 0 927.168 0 463.584 463.584 0 1 0-927.168 0Z\"fill=\"#00A2FF\"p-id=\"7645\"></path><path d=\"M49.144 538.188a469.72 469.72 0 0 1-0.728-26.188c0-65.248 13.508-127.368 37.88-183.708l14.12-4.708 40 42-8 86-83.272 86.604z m121.588 287.444c-67.904-73.84-112.18-169.74-120.784-275.664 45.864-5.224 114.468-10.592 114.468-10.592l52 88h32l28 36.208-105.684 162.048z m3.664-631.204l85.42-2.844v48l-60.232 124-44-4-36.432-93.688a465.98 465.98 0 0 1 55.244-71.468z m801.072 328.056l-11.884-4.484h-83.088a11.676 11.676 0 0 1-8.344-3.508l-102.94-105.08a11.68 11.68 0 0 0-17.764 1.268l-22.232 30.316a11.68 11.68 0 0 0 9.42 18.588h27.364c3.532 0 6.876 1.6 9.092 4.348l91.472 113.424a11.68 11.68 0 0 1 1.028 13.164l-144.636 251.212a11.68 11.68 0 0 1-10.124 5.852h-29.764a11.68 11.68 0 0 1-10.612-6.796l-85.744-186.404a11.68 11.68 0 0 0-10.612-6.8h-50.352a11.672 11.672 0 0 1-9.64-5.084l-46.48-67.932a11.672 11.672 0 0 1-2.044-6.596v-45.632c0-2.8 1.008-5.508 2.836-7.628l33.672-39.072a11.684 11.684 0 0 1 8.848-4.056h111.812a11.692 11.692 0 0 0 10.184-5.952l22.856-40.64a11.676 11.676 0 0 0-10.18-17.408h-130.472a11.68 11.68 0 0 1-10.776-16.192l62.22-148.636a11.684 11.684 0 0 1 10.776-7.172h236.932a11.68 11.68 0 0 0 11.268-14.752l-3.952-14.492a11.692 11.692 0 0 1 11.272-14.756h12.028C926.6 274.856 975.584 387.752 975.584 512c0 3.504-0.036 7-0.116 10.484z m-175.884 273.1l32 4-56 48v-20l24-32z\"fill=\"#00E116\"p-id=\"7646\"></path><path d=\"M802.936 151.164c105.272 85.012 172.648 215.12 172.648 360.836 0 255.86-207.724 463.584-463.584 463.584-142.388 0-269.868-64.332-354.936-165.488 79.572 64.256 180.796 102.748 290.936 102.748 255.86 0 463.584-207.724 463.584-463.584 0-113.472-40.856-217.48-108.648-298.096z\"fill-opacity=\".2\"p-id=\"7647\"></path></svg>");
            aiDrawServer.setServerStatus(0);
            aiDrawServer.setCreateTime(new Date());
            aiDrawServerService.save(aiDrawServer);
        }
    }
}
